﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:asp="remove">
  <xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/>

  <!--<xsl:param name="employeeId"/>-->
  <xsl:param name="employeeId"/>
  <xsl:template match="/root">
    <xsl:for-each select="Employee">
      <xsl:if test="@Id = $employeeId">
        <table width="100%" border="0"
               cellspacing="0" cellpadding="0"
               bgcolor="#FFFFFF">
          <tbody>
            <tr>
              <td>
                <xsl:apply-templates  select="Address">
                  <!--<xsl:with-param name="count" 
                           select="$count"/>-->
                </xsl:apply-templates>
              </td>
            </tr>
            <tr>
              <td>&#160;</td>
            </tr>
            <tr>
              <td align="right">
                <span style="margin-right:20%">
                  <asp:Button ID="btnSaveAddress"
                    runat="server" BackColor="White"
                    BorderColor="DeepSkyBlue" BorderStyle="Solid"
                    BorderWidth="1px" Font-Names="Tahoma"
                    Font-Size="10pt" Text="Save Data" />
                </span>
                <span>&#160;</span>
              </td>
            </tr>
          </tbody>
        </table>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>
  <xsl:template name="HomeAddress"
           match="/root/Employee/Address">
    <table width="100%">
      <tr>
        <td height="30" colspan="2" align="left">
          <strong>
            <xsl:value-of select="@Caption"/>
          </strong>
        </td>
      </tr>
      <tr>
        <td height="2" colspan="2"
               align="left" bgcolor="#CCCC99"></td>
      </tr>
      <tr>
        <td width="50%" height="30"
                  align="left" valign="top">
          <table width="100%" border="0"
                  cellspacing="0" cellpadding="0">
            <tr>
              <td colspan="4" height="4"></td>
            </tr>
            <tr>
              <xsl:for-each select="child::*">
                <xsl:variable name="rowindex"
                       select="position()"></xsl:variable>
                <td align="left" valign="top">
                  <table cellpadding="4">
                    <tr>
                      <td colspan="4" height="28"
                              align="left" valign="top">
                        <strong>
                          <xsl:value-of select="@Caption"/>
                        </strong>
                      </td>
                    </tr>
                    <xsl:for-each select="child::*">
                      <xsl:variable name="varType"
                           select="@Type"></xsl:variable>
                      <xsl:variable name="isRequired"
                           select="@Required"></xsl:variable>
                      <xsl:variable name="varId"
                         select="translate(concat(concat(concat(@Caption,'_'), 
                                         $rowindex),position()),'  ','_')">
                      </xsl:variable>
                      <xsl:variable name="up"
                        select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
                      <xsl:variable name="lo"
                        select="'abcdefghijklmnopqrstuvwxyz'"/>
                      <tr>
                        <td height="28" align="left" valign="top">
                          <xsl:value-of select="@Caption"/>
                        </td>
                        <td colspan="3" align="left"
                           valign="top" height="28">
                          <xsl:choose>
                            <xsl:when test="translate($varType,$up,$lo)='countryddl'">
                              <asp:DropDownList id="{concat('ddlCountry',$rowindex)}"
                                     runat="server" DataTextField="Text"
                                     DataValueField="Value">
                                <asp:ListItem value="{.}">
                                  <xsl:value-of select="."/>
                                </asp:ListItem>
                              </asp:DropDownList>
                            </xsl:when>
                            <xsl:otherwise>
                              <asp:TextBox ID="{$varId}"
                                   runat="server" Text="{.}"
                                   width="205px" ></asp:TextBox>
                              <xsl:if test="translate($isRequired,$up,$lo)='yes'">
                                <asp:RequiredFieldValidator
                                  ErrorMessage="Required Field" runat="server"
                                  ControlToValidate="{$varId}" />
                              </xsl:if>
                            </xsl:otherwise>
                          </xsl:choose>
                        </td>
                      </tr>
                    </xsl:for-each>
                  </table>
                </td>
              </xsl:for-each>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </xsl:template>
</xsl:stylesheet>
